/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;


@Entity
@Table(name = "SONG")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Song.findAll", query = "SELECT s FROM Song s"),
    @NamedQuery(name = "Song.findBySongId", query = "SELECT s FROM Song s WHERE s.songId = :songId"),
    @NamedQuery(name = "Song.findBySongTitle", query = "SELECT s FROM Song s WHERE s.songTitle = :songTitle"),
    @NamedQuery(name = "Song.findByTrackNumber", query = "SELECT s FROM Song s WHERE s.trackNumber = :trackNumber"),
    @NamedQuery(name = "Song.findByDuration", query = "SELECT s FROM Song s WHERE s.duration = :duration"),
    @NamedQuery(name = "Song.findByCreatedBy", query = "SELECT s FROM Song s WHERE s.createdBy = :createdBy"),
    @NamedQuery(name = "Song.findByCreatedDate", query = "SELECT s FROM Song s WHERE s.createdDate = :createdDate"),
    @NamedQuery(name = "Song.findByModifiedBy", query = "SELECT s FROM Song s WHERE s.modifiedBy = :modifiedBy"),
    @NamedQuery(name = "Song.findByModifiedDate", query = "SELECT s FROM Song s WHERE s.modifiedDate = :modifiedDate")})
public class Song implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "SONG_ID")
    private Long songId;
    @Basic(optional = false)
    @Column(name = "SONG_TITLE")
    private String songTitle;
    @Basic(optional = false)
    @Column(name = "TRACK_NUMBER")
    private int trackNumber;
    @Basic(optional = false)
    @Column(name = "DURATION")
    private int duration;
    @Basic(optional = false)
    @Column(name = "CREATED_BY")
    private String createdBy;
    @Basic(optional = false)
    @Column(name = "CREATED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate;
    @Column(name = "MODIFIED_BY")
    private String modifiedBy;
    @Column(name = "MODIFIED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modifiedDate;
    @JoinColumn(name = "ALBUM_ID", referencedColumnName = "ALBUM_ID")
    @ManyToOne(optional = false)
    private Album albumId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "songId")
    private List<Playlistsong> playlistsongList;

    public Song() {
    }

    public Song(Long songId) {
        this.songId = songId;
    }

    public Song(Long songId, String songTitle, int trackNumber, int duration, String createdBy, Date createdDate) {
        this.songId = songId;
        this.songTitle = songTitle;
        this.trackNumber = trackNumber;
        this.duration = duration;
        this.createdBy = createdBy;
        this.createdDate = createdDate;
    }

    public Long getSongId() {
        return songId;
    }

    public void setSongId(Long songId) {
        Long oldSongId = this.songId;
        this.songId = songId;
        changeSupport.firePropertyChange("songId", oldSongId, songId);
    }

    public String getSongTitle() {
        return songTitle;
    }

    public void setSongTitle(String songTitle) {
        String oldSongTitle = this.songTitle;
        this.songTitle = songTitle;
        changeSupport.firePropertyChange("songTitle", oldSongTitle, songTitle);
    }

    public int getTrackNumber() {
        return trackNumber;
    }

    public void setTrackNumber(int trackNumber) {
        int oldTrackNumber = this.trackNumber;
        this.trackNumber = trackNumber;
        changeSupport.firePropertyChange("trackNumber", oldTrackNumber, trackNumber);
    }

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        int oldDuration = this.duration;
        this.duration = duration;
        changeSupport.firePropertyChange("duration", oldDuration, duration);
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        String oldCreatedBy = this.createdBy;
        this.createdBy = createdBy;
        changeSupport.firePropertyChange("createdBy", oldCreatedBy, createdBy);
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        Date oldCreatedDate = this.createdDate;
        this.createdDate = createdDate;
        changeSupport.firePropertyChange("createdDate", oldCreatedDate, createdDate);
    }

    public String getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        String oldModifiedBy = this.modifiedBy;
        this.modifiedBy = modifiedBy;
        changeSupport.firePropertyChange("modifiedBy", oldModifiedBy, modifiedBy);
    }

    public Date getModifiedDate() {
        return modifiedDate;
    }

    public void setModifiedDate(Date modifiedDate) {
        Date oldModifiedDate = this.modifiedDate;
        this.modifiedDate = modifiedDate;
        changeSupport.firePropertyChange("modifiedDate", oldModifiedDate, modifiedDate);
    }

    public Album getAlbumId() {
        return albumId;
    }

    public void setAlbumId(Album albumId) {
        Album oldAlbumId = this.albumId;
        this.albumId = albumId;
        changeSupport.firePropertyChange("albumId", oldAlbumId, albumId);
    }

    @XmlTransient
    public List<Playlistsong> getPlaylistsongList() {
        return playlistsongList;
    }

    public void setPlaylistsongList(List<Playlistsong> playlistsongList) {
        this.playlistsongList = playlistsongList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (songId != null ? songId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Song)) {
            return false;
        }
        Song other = (Song) object;
        if ((this.songId == null && other.songId != null) || (this.songId != null && !this.songId.equals(other.songId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Model.Song[ songId=" + songId + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
